import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [react()],
    resolve: {
        // 设置文件./src路径为 @
        alias: [
            {
                find: '@',
                replacement: resolve(__dirname, './src')
            }
        ]
    },
    // server: {
    //     proxy: {
    //         '/api': {
    //             target: 'http://123.56.100.154:8081',
    //             changeOrigin: true,
    //             rewrite: (path) => path.replace(/^\/api/, '')
    //         }
    //     }
    // },
    optimizeDeps: {
        include: ['events'],
    },
    css: {
        modules: {
            // 自定义生成的类名格式
            generateScopedName: '[name]__[local]___[hash:base64:5]'
        },
        preprocessorOptions: {
            less: {
                javascriptEnabled: true,
                // 全局变量
                modifyVars: {
                    // 在这里添加全局变量
                },
                additionalData: `@import "@/styles/index.less";`
            }
        }
    },
    // SSR 相关配置
    ssr: {
        // 防止外部化列出的依赖项
        noExternal: ['antd', '@ant-design/icons','@ant-design/icons-svg','rc-util', 'rc-*']
    },
    base: './',
    build: {
        rollupOptions: {
            output: {
                manualChunks: {
                    'tiptap': ['@tiptap/react', '@tiptap/starter-kit', '@tiptap/extension-bubble-menu'],
                }
            }
        }
    }
})
